﻿Public Class DparametroSistDet

    Public Shared Function SeleccionarTodoXParametroSist(ByVal descEmpresa As String, ByVal idParametroSist As Int32) As List(Of EparametroSistDet)
        Dim parametros As List(Of EparametroSistDet) = Nothing

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_parametroSistDet_selXParametroSist", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@idParametroSist", SqlDbType.Int).Value = idParametroSist
                Try
                    cn.Open()
                    Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.SingleResult Or CommandBehavior.CloseConnection)
                        If dr.HasRows Then
                            parametros = New List(Of EparametroSistDet)
                            Dim parametro As EparametroSistDet = Nothing
                            Do While dr.Read
                                parametro = New EparametroSistDet( _
                                    dr.GetInt32(dr.GetOrdinal("idParametroSist")), _
                                    dr.GetInt32(dr.GetOrdinal("idParametroSistDet")), _
                                    dr.GetString(dr.GetOrdinal("descParametroSistDet")), _
                                    dr.GetString(dr.GetOrdinal("aliasParametroSistDet")), _
                                    dr.GetInt16(dr.GetOrdinal("valor")), _
                                    dr.GetString(dr.GetOrdinal("estado")))
                                parametros.Add(parametro)
                            Loop
                            dr.Close()
                        End If
                    End Using
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return parametros
    End Function
    Public Shared Function Añadir(ByVal descEmpresa As String, ByVal ent As EparametroSistDet) As Boolean
        Dim resultado As Boolean = False

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_parametroSistDet_add", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@idParametroSist", SqlDbType.Int).Value = ent.idParametroSist
                cmd.Parameters.Add("@descParametroSistDet", SqlDbType.VarChar, 55).Value = ent.descParametroSistDet
                cmd.Parameters.Add("@aliasParametroSistDet", SqlDbType.VarChar, 55).Value = ent.aliasParametroSistDet
                cmd.Parameters.Add("@valor", SqlDbType.SmallInt).Value = ent.valor
                cmd.Parameters.Add("@estado", SqlDbType.Char, 1).Value = ent.estado
                Try
                    cn.Open()
                    cmd.ExecuteNonQuery()
                    resultado = True
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return resultado
    End Function
    Public Shared Function Editar(ByVal descEmpresa As String, ByVal ent As EparametroSistDet) As Boolean
        Dim resultado As Boolean = False

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_parametroSistDet_edit", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@idParametroSistDet", SqlDbType.VarChar, 55).Value = ent.idParametroSistDet
                cmd.Parameters.Add("@descParametroSistDet", SqlDbType.VarChar, 55).Value = ent.descParametroSistDet
                cmd.Parameters.Add("@aliasParametroSistDet", SqlDbType.VarChar, 55).Value = ent.aliasParametroSistDet
                cmd.Parameters.Add("@valor", SqlDbType.Int).Value = ent.valor
                cmd.Parameters.Add("@estado", SqlDbType.Char, 1).Value = ent.estado
                Try
                    cn.Open()
                    cmd.ExecuteNonQuery()
                    resultado = True
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return resultado
    End Function

End Class
